package main

import (
	"context"
	greeter "go_final/demos/grpc_metadata/protofile"

	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
)

func main() {
	conn, err := grpc.Dial(":8080", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	c := greeter.NewGreeterClient(conn)

	// 生成metadata的方式1
	md1 := metadata.New(map[string]string{
		"token": "1234567890",
	})

	// 生成metadata的方式2
	/**
	md2 := grpc_metadata.Pairs(
		"key1", "val1",
		"key2", "val2",
		)
	*/
	// 发送metadata
	ctx := metadata.NewOutgoingContext(context.Background(), md1)

	c.SayHi(ctx, &greeter.SayHiRequest{
		Id: "Felix",
	})
}
